<template>
  <div class="container">
    <header class="header">
      <h1>{{ data.title }}</h1>
      <div class="time-info">赛前 8 小时前</div>
    </header>

    <section class="match-info">
      <div class="list" v-for="item in data.matchList" :key="item.id">
        <div class="date-time">
          <span>{{ item.leagueName }}</span>
          <span>{{ formateTime(item.matchTime) }}</span>
          <span class="status">{{ item.matchStatusDesc }}</span>
        </div>
        <div class="teams">
          <div class="team">
            <span>{{ item.hostTeamName }}</span> <img :src="item.hostTeamLogo" alt="" />
          </div>
          <div class="vs">VS</div>
          <div class="team">
            <img :src="item.guestTeamLogo" alt="" />
            <span>{{ item.guestTeamName }}</span>
          </div>
        </div>
        <div class="odds">
          <div class="option">
            <button>竞彩{{ item?.matchOdds?.handicap }}</button>
          </div>
          <div class="odds-values">
            <span class="win">胜{{ item?.matchOdds?.win }}</span>
            <span class="draw">平{{ item?.matchOdds?.draw }}</span>
            <span class="lose">负{{ item?.matchOdds?.lose }}</span>
          </div>
        </div>
      </div>
    </section>

    <section class="purchase-info">
      <p class="purchase-title">扫码下载APP有料版，立即解锁推荐详情</p>
      <div class="purchase-detail">
        <div class="countdown">
          <span class="countdown-title">距离方案截止</span>
          <div class="timer">
            <span>{{ daysRef }}</span
            >: <span>{{ hoursRef }}</span
            >: <span>{{ minutesRef }}</span
            >:
            <span>{{ secondsRef }}</span>
          </div>
        </div>
        <!-- <div class="unlock">
          <span>解锁方案需83球钻</span>
          <button>立即支付</button>
        </div> -->
      </div>
    </section>
  </div>
</template>
<script setup>
import { onUnmounted, ref, watch } from 'vue'
import { defineProps } from 'vue'
import { useCountdown } from '@/utils/useCountdown'
import dayjs from 'dayjs';
const dataRef = ref({})

const targetTime = ref(0)
// const { days, hours, minutes, seconds } =
const daysRef = ref(0)
const hoursRef = ref(0)
const minutesRef = ref(0)
const secondsRef = ref(0)
const formateTime = (num) => {
  return dayjs(num).format('YYYY-MM-DD HH:mm:ss')
}
let intervalId = null
// days.value = days.value
// hours.value = hours.value
// minutes.value = minutes.value
// seconds.value = seconds.value
const props = defineProps({
  data: {
    type: Object,
    default: () => ({})
  }
})

watch(
  () => props.data,
  (newVal) => {
    dataRef.value = newVal
    console.log(newVal?.matchList[0]?.matchTime)

    intervalId = setInterval(() => {
      const { days, hours, minutes, seconds } = useCountdown(newVal?.matchList[0]?.matchTime)
      daysRef.value = days.value
      hoursRef.value = hours.value
      minutesRef.value = minutes.value
      secondsRef.value = seconds.value
    }, 1000)
  }
)
onUnmounted(() => {
  if (intervalId) {
    clearInterval(intervalId)
  }
})

// You can define any reactive state or logic here if needed.
</script>
<style scoped lang="scss">
.container {
  width: 854px;
  padding: 40px;
  background-color: #fff;
  font-family: Arial, sans-serif;
  border-radius: 10px;
  margin-left: 20px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.header {
  //   text-align: center;
  margin-bottom: 20px;

  h1 {
    font-size: 24px;
    font-weight: bold;
    margin-bottom: 5px;
  }

  .time-info {
    color: #888;
    font-size: 14px;
  }
}

.match-info {
  background: white;
  border-radius: 10px;
  margin-bottom: 20px;
  //   box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);

  .list {
    margin-bottom: 20px;
    border-radius: 10px 10px 10px 10px;
    border: 1px solid #f6f8ff;
  }
  .date-time {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    background: #f6f8ff;
    width: 100%;
    padding: 10px 20px;

    span {
      font-family:
        PingFang SC,
        PingFang SC;
      font-weight: 800;
      font-size: 12px;
      color: #afb8cb;
    }

    .status {
      background: #16b13a;
      border-radius: 20px 20px 20px 20px;
      color: #fff;
      width: 64px;
      height: 28px;
      line-height: 28px;
      text-align: center;
    }
  }

  .teams {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 20px;

    .team {
      text-align: center;
      display: flex;
      justify-content: center;
      align-items: center;
      img {
        width: 50px;
        height: 50px;
        object-fit: cover;
        border-radius: 50%;
        // margin-bottom: 5px;
      }

      span {
        display: block;
        font-size: 18px;
        font-weight: bold;
        width: 130px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
    }

    .vs {
      font-size: 20px;
      margin: 0 20px;
      width: 100px;
      text-align: center;
    }
  }

  .odds {
    display: flex;
    justify-content: center;
    align-items: center;
    padding-bottom: 20px;

    .option {
      button {
        width: 120px;
        height: 36px;
        border-radius: 6px 6px 6px 6px;
        border: 1px solid #e2eeff;
        line-height: 36px;
        text-align: center;
        margin-right: 10px;
      }
    }

    .odds-values {
      display: flex;
      //   justify-content: space-between;
      align-items: center;
      //   width: 50%;

      span {
        font-size: 16px;
        font-weight: bold;
        width: 120px;
        height: 36px;
        border-radius: 6px 6px 6px 6px;
        border: 1px solid #e2eeff;
        line-height: 36px;
        text-align: center;
        margin-right: 10px;
        font-family:
          PingFang SC,
          PingFang SC;
        font-weight: 400;
        font-size: 14px;
        color: #afb8cb;
        &:last-child {
          margin-right: 0;
        }
      }
    }
  }
}

.purchase-info {
  text-align: center;
  //   background: white;
  padding: 20px;
  //   border-radius: 10px;
  //   box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);

  .purchase-title {
    font-family:
      PingFang SC,
      PingFang SC;
    font-weight: 800;
    font-size: 16px;
    color: #e95d5d;
    margin-bottom: 20px;
  }
  .purchase-detail {
    background: url('@/assets/imgs/info-detail-bg.webp') no-repeat center center;
    background-size: 100% 100%;
    padding: 20px;
    height: 300px;
  }
  .countdown {
    margin-bottom: 20px;
    width: 308px;
    height: 116px;
    margin: 60px auto 0;
    background: #e2eeff;
    border-radius: 10px 10px 10px 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    .countdown-title {
      font-size: 14px;
      color: #e95d5d;
    }
    span {
      display: block;
      font-size: 14px;
      margin-bottom: 5px;
    }

    .timer {
      font-size: 24px;
      font-weight: bold;
      display: flex;
      align-items: center;
      justify-content: center;
      span {
        margin: 0 5px;
        width: 40px;
        height: 40px;
        background: #e95d5d;
        border-radius: 6px 6px 6px 6px;
        color: #fff;
        line-height: 40px;
        text-align: center;
      }
    }
  }

  .unlock {
    display: flex;
    justify-content: space-between;
    align-items: center;

    span {
      font-size: 14px;
    }

    button {
      background-color: #ff4d4f;
      color: white;
      border: none;
      border-radius: 5px;
      padding: 10px 20px;
      font-size: 16px;
      cursor: pointer;
    }
  }
}
</style>
